package com.world.login.controller;

import com.world.common.annotation.AnonymousAccess;
import com.world.common.domain.ResponseData;
import com.world.common.domain.SuccessResponseData;
import com.world.login.domain.query.LoginRequest;
import com.world.login.domain.vo.LoginResultVO;
import com.world.login.service.ILoginService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 登录
 *
 * @author WangYX
 * @version 1.0.0
 * @date 2023/06/01 10:06
 */
@Slf4j
@Api(tags = "登录")
@RestController
@RequestMapping("/login")
public class LoginController {

    @Resource
    private ILoginService loginService;

    /**
     * 登录
     *
     * @param request 请求参数
     * @return {@link ResponseData}
     * @author WangYX
     * @date 2023/06/01 10:59
     */
    @AnonymousAccess
    @PostMapping("")
    public ResponseData<LoginResultVO> login(@RequestBody LoginRequest request) {
        log.info("请求参数：{}", request);
        return new SuccessResponseData<>(LoginResultVO.builder().token(loginService.login(request)).build());
    }

    /**
     * 退出登录
     *
     * @author WangYX
     * @date 2023/10/07 11:27
     */
    @PutMapping("/logout")
    public ResponseData<Void> logout() {
        loginService.logout();
        return new SuccessResponseData<>();
    }
}



